var app = getApp();
var common = require('../../utils/util.js');
var isInit = true;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    banner: ['http://furnish.house365.com/upload/furnishing/2022/0615/15/20220615150136_38923.jpg', 'http://furnish.house365.com/upload/furnishing/2022/0615/15/20220615150136_38923.jpg'],
    // todo 图标
    icon: [
      {
        face: 'http://wokewl.oss-cn-hangzhou.aliyuncs.com/wky_video/7b7d5a1e7f37c9d65008386b4afb6d4f3b36c643.png',
        title: '发布资讯',
        url: '/pages/news/editNews'
      },
      {
        face: 'http://wokewl.oss-cn-hangzhou.aliyuncs.com/wky_video/7b7d5a1e7f37c9d65008386b4afb6d4f3b36c643.png',
        title: '发布跑腿',
        url: '/pages/order/publish'
      }
    ],
    news: [],
    current: 0,
  },

  onLoad: function () {
    this.getNewsList();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let userInfo = wx.getStorageSync('userInfo');
    if(isInit && userInfo.account_type && userInfo.account_type==2) {
      isInit = false;
      let icon = this.data.icon;
      icon.push({
        face: 'http://wokewl.oss-cn-hangzhou.aliyuncs.com/wky_video/7b7d5a1e7f37c9d65008386b4afb6d4f3b36c643.png',
        title: '我要帮忙',
        url: '/pages/order/order?tab=1&ordertype=accept'
      })
      this.setData({
        icon
      })
    }
  },
  swiperChange: function (e) {
    this.setData({
      current: e.detail.current,
    });
  },
  getNewsList: function () {
    wx.showLoading({
      title: '加载中...',
    });
    var that = this;
    common.getData_user(
      common.config.HotNewsList, {},
      "post",
      function (res) {
        wx.hideLoading();
        that.setData({
          news: res && res.list || []
        });
      }
    );
  },
  onHref(e) {
    let {url, id} = e.currentTarget.dataset;
    wx.navigateTo({
      url: `${url}?id=${id}`,
    });
  },
});